package com.bookstore.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bookstore.model.User;
import com.bookstore.service.ServiceFactory;
import com.bookstore.service.UserService;

@WebServlet("/listUser.do")
public class UserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public UserServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		UserService userService = ServiceFactory.getUserService();
		try {
			List<User> list = userService.findAll();
			request.setAttribute("userList", list);
			request.getRequestDispatcher("/WEB-INF/view/users.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
